﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBModel;

namespace CV_Projekt
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {


                var user = Session["User"];



                if (user == null)
                {
                    ButtonLogOut.Text = "Logga in";
                }
                else
                {
                    ButtonLogOut.Text = "Logga ut";
                }

                if (user is Applicant)
                {
                    var appUser = (Applicant)user;
                    ButtonUser.Text = string.Format("[{0} {1}]", appUser.FirstName, appUser.LastName);
                }
                else if (user is SuperAdmin)
                {                  
                    var saUser = (DBModel.SuperAdmin)user;
                    ButtonUser.Text = string.Format("[{0}]", saUser.UserName);
                }
                else if (user is HeadHunter)
                {            
                    var headHunterUser = (HeadHunter)user;
                    ButtonUser.Text = string.Format("[{0}]", headHunterUser.HeadHunterName);
                }
                else if (user is Publisher)
                {
                    var publisher = (Publisher)user;
                    ButtonUser.Text = string.Format("[{0}]", publisher.EmployerName);
                }


            }


        }

        protected void ButtonLogOut_Click(object sender, EventArgs e)
        {
            var user = Session["User"] as User;

            if (user != null)
            {
                Session["User"] = null;
                Response.Redirect("Default.aspx");
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
    }
}